package com.yoshino.leetcode.oneHundred.tenth;

import java.util.HashSet;
import java.util.Set;

class Solution {
    //0 <= num < 2^31
    public int translateNum(int num) {
        // 状态方程： T[i] = T[i - 1] + T[i - 2] 需要加入判断
        if (num < 10) {
            return 1;
        }
        String param = String.valueOf(num);
        int[] dp = new int[param.length()];
        dp[0] = dp[1] = 1;
        for (int i = 2; i < param.length(); i++) {
            String sub = param.substring(i - 2, i);
            if (sub.compareTo("10") >= 0 && sub.compareTo("25") <= 0) {
                dp[i] = dp[i - 2] + dp[i - 1];
            } else {
                dp[i] = dp[i - 1];
            }
        }
        return dp[param.length() - 1];
    }

    public int lengthOfLongestSubstring(String s) {
        int res = 0, l = 0;
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            while (set.contains(c)) {
                set.remove(s.charAt(l++));
            }
            set.add(c);
            res = Math.max(res, i - l + 1);
        }
        return res;
    }
}
